package com.funtonow.jqdk.adapter;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.funtonow.jqdk.R;
import com.funtonow.jqdk.bean.ApplyRecordBean;
import com.funtonow.jqdk.utils.GlideUtils;
import com.funtonow.jqdk.utils.StringUtil;
import com.funtonow.jqdk.utils.TimeUtils;
import com.shehuan.niv.NiceImageView;

import java.util.Locale;

/**
 * @author Jiajien
 * @date 2019/6/26
 */
public class ApplyRecordAdapter extends BaseQuickAdapter<ApplyRecordBean.DataBean, BaseViewHolder> {


    public ApplyRecordAdapter() {
        super(R.layout.item_apply_record);
    }

    @Override
    protected void convert(BaseViewHolder helper, ApplyRecordBean.DataBean item) {
        NiceImageView niceImageView = helper.getView(R.id.iv_apply_img);
        LinearLayout llApplyTime = helper.getView(R.id.ll_apply_time);
        LinearLayout llSelectResult = helper.getView(R.id.ll_select_result);
        TextView tvPaymentTime = helper.getView(R.id.tv_payment_time);
        TextView tvUpdatePaymentTime = helper.getView(R.id.tv_update_payment_time);
        GlideUtils.setHeadImg(niceImageView, item.getChanpin().getIcon());
        helper.setText(R.id.tv_apply_name, item.getChanpin().getName())
                .setText(R.id.tv_apply_time, String.format(Locale.getDefault(),
                        "申请时间：%s", TimeUtils.longToString(item.getSq().getTime())))
                .addOnClickListener(R.id.tv_apply_agree)
                .addOnClickListener(R.id.tv_apply_refuse)
                .addOnClickListener(R.id.tv_apply_abandon)
                .addOnClickListener(R.id.tv_update_payment_time);
        if (StringUtil.isEmpty(item.getSq().getState())) {
            llSelectResult.setVisibility(View.VISIBLE);
            llApplyTime.setVisibility(View.GONE);
        } else {
            llApplyTime.setVisibility(View.VISIBLE);
            llSelectResult.setVisibility(View.GONE);
            helper.setText(R.id.tv_apply_state, item.getSq().getState());
            if ("已下款".equals(item.getSq().getState())) {
                tvUpdatePaymentTime.setVisibility(View.VISIBLE);
                if (StringUtil.isEmpty(item.getSq().getHuan())) {
                    tvPaymentTime.setVisibility(View.INVISIBLE);
                    tvUpdatePaymentTime.setText("设置还款提醒");
                } else {
                    tvPaymentTime.setVisibility(View.VISIBLE);
                    tvPaymentTime.setText(String.format("还款日：%s", item.getSq().getHuan()));
                    tvUpdatePaymentTime.setText("修改");
                }
            } else {
                tvPaymentTime.setVisibility(View.GONE);
                tvUpdatePaymentTime.setVisibility(View.GONE);
            }
        }


    }
}
